package com.cloud.salon.client.menber;

import com.cloud.salon.client.menber.service.AccountService;
import com.cloud.salon.client.menber.service.StaffService;
import com.cloud.salon.common.base.entity.menber.Account;
import com.cloud.salon.common.base.entity.menber.Staff;
import com.cloud.salon.common.base.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/*
 * @Description 成员管理微服务
 * @Author wolf--LZH
 * @CreateDate 2019/4/26 0026 下午 9:56
 */
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
@EntityScan("com.cloud.salon.common.base.entity")
@ComponentScan(basePackages = {"com.cloud.salon"})
@RestController
public class SalonClientMenberApplication {

    public static void main(String[] args) {
        SpringApplication.run(SalonClientMenberApplication.class, args);
    }


    @Autowired
    AccountService accountService;
    @Autowired
    StaffService staffService;

    @RequestMapping("/account/general")
    public String generalAccount() {

        String startStr = "2018-01-01";
        String endStr = "2019-05-19";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyMMdd");
        long start = 0;
        long end = 0;
        try {
            start = sdf.parse(startStr).getTime();
            end = sdf.parse(endStr).getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }

        int index = 100 - (int)(Math.random() * 10);

        List<Account> accounts = new ArrayList<>();
        for (int i = 0; i < index; i++) {
            Account account = new Account();
            account.setName("会员" + (i + 1));
            account.setBalance((int)(Math.random() * 2000) / 10.0);

            Date date = new Date(start + (long)(Math.random() * (end - start)));
            account.setNumber(sdf2.format(date) + (int)(Math.random() * Math.pow(10, 4)));
            account.setCreateTime(date);

            accounts.add(account);
        }

        accountService.saveAll(accounts);
        return "done";
    }

    @RequestMapping("/staff/general")
    public String generalStaff() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyMMdd");
        String birSS = "1990-01-01";
        String birES = "1998-02-17";
        String startStr = "2018-01-01";
        String endStr = "2019-05-19";
        long start = 0;
        long end = 0;
        long birS = 0;
        long birE = 0;
        try {
            start = sdf.parse(startStr).getTime();
            end = sdf.parse(endStr).getTime();
            birS = sdf.parse(birSS).getTime();
            birE = sdf.parse(birES).getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<Staff> staffs = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            Staff staff = new Staff();

            staff.setUserId(i);
            staff.setAddress("地址" + i);
            staff.setName("员工" + i);
            staff.setQQ("QQ" + i);
            staff.setEmail("email" + i);
            staff.setRemark("备注" + i);
            staff.setSex((int)(Math.random() * 2));


            Date date = new Date(start + (long)(Math.random() * (end - start)));
            Date birD = new Date(birS + (long)(Math.random() * (birE - birS)));
            staff.setNumber(sdf2.format(date) + (int)(Math.random() * Math.pow(10, 4)));
            staff.setJoinDate(date);
            staff.setBirthday(birD);
            staff.setIdNumber(String.valueOf((int)(Math.random() * Math.pow(10, 9))) + String.valueOf((int)(Math.random() * Math.pow(10, 9))));
            staff.setPhone(String.valueOf((int)(Math.random() * Math.pow(10, 11))));


            staffs.add(staff);
        }

        staffService.saveAll(staffs);
        return "done";
    }



}
